package ly.gupao.edu.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Author: LiYang
 * @created on: 2018/5/27 17:48
 * @discribe:
 */
public class TcpServerDemo {

    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8081);
        Socket socket = serverSocket.accept();
        //获取输入流
        BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String str = reader.readLine();
        System.out.println("client--:" + str);
        //构建输出数据
        BufferedReader reader1 = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter writer = new PrintWriter(socket.getOutputStream());
        while(str != "bye"){
            writer.write(reader1.readLine());
            writer.flush();
            System.out.println("client--:" + str);
            str = reader.readLine();
        }
        serverSocket.close();
        socket.close();
        reader.close();
    }
}
